
********************************************************************************
* Analysis Code for CES Substitutability Experiment
********************************************************************************

* Paul Musgrave
* rpm47@georgetown.edu
* For Paul Musgrave and Dov Levin

********************************************************************************
* Stata Packages Required (Note)
********************************************************************************

/*

Replication users will need the following packages available from SSC or other
repositories

net install cleanplots, from("https://tdmize.github.io/data/cleanplots") replace

ssc install catplot

ssc install coefplot

ssc install esttab

ssc install mylabels

ssc install grc1leg

ssc install statplot

*/


********************************************************************************
* Stata Cruft
********************************************************************************

clear all

version 18

set more off


set scheme plotplainblind


******** EDIT DIRECTORY STRUCTURE TO FIT YOUR COMPUTER ********

global MyProject "~/Dropbox/0001 Academic Projects/Ongoing/0155 Voting Abroad Purpose/Replication/Upload/"


use "${MyProject}CCES2022processedUPLOAD.dta", clear

* Hegemony

clonevar hegemony_concern = UMA315
lab var hegemony_concern "US Strengthening or Weakening"

* News interest

clonevar newsint_num = newsint
recode newsint_num (4 = 3) (7 = .)
lab def NEWSINT 3 "Now and then / hardly at all", modify

	

********************************************************************************
* Descriptive Plots
********************************************************************************

/// Figure 6 A) 

	
* Descriptive plot of Most Preferred Intervention

catplot  					 													///
	, over(subs_DV_main, label(labsize(*.65)))									///
	over(subs_treatment, label(labsize(2)))										///
	asyvars stack																///
	bar(1, bcolor(ebg)) bar(2, bcolor(dimgray)) 								///
	horizontal percent(subs_treatment) 											///
	ytitle("Percent") 															///
	blabel(bar,format(%4.1f) box margin(".5 .5 .5 .5") fcolor(white) color(black) size(2) position(center)) 							///
	legend(position(12) rows(1) size(vsmall)) name(gph_subs_treatment,replace)				///
	title("{bf:A) Most Preferred Intervention by Treatment, Substitutability Scenario}")	///
	note("N = 830", size(small))
	
	

********************************************************************************
* Multinomial logistic regression
********************************************************************************

* Treatment only

mlogit 	subs_DV_main b2.subs_treatment
est sto subs_base_mlog, title("Base, Mlogit")
local subs_base_mlogN = e(N)

* With demographics
mlogit 	subs_DV_main b2.subs_treatment 											///
						age white female college i.pid7
est sto subs_adj_mlog, title("Adj, Mlogit")
local 	subs_adj_mlogN = e(N)

* Coefplot (Figure 6 b)

coefplot																		///
			(subs_base_mlog, label(Base)) (subs_adj_mlog, label(Covariates)), 	///
				keep(Intervention_anytime: *subs*) bylabel("Intervention anytime") ///
				legend(pos(12) rows(1) size(small))||	///
			(subs_base_mlog, label(Base)) (subs_adj_mlog, label(Covariates)), 	///
				keep(Post_electoral_intervention: *subs*) bylabel("Post-Election")	||	///
			(subs_base_mlog, label(Base)) (subs_adj_mlog, label(Covariates)), 	///
				keep(Electoral_intervention: *subs*) bylabel("Pre-Election")	||	///
			, drop(_cons)	base	omitted											///
			ylab(,labsize(vsmall))	xline(0)									///
				name(gph_overall, replace)										///
			byopts(																///
				compact rows(1) 												///
				title("{bf: B) Effects of Treatment on Intervention Support}", span) ///
				subtitle("{it:Multinomial Logistic Regression Coefficients Shown; Base Outcome is No Intervention}", size(vsmall))	///
				note("2022 CES Substitutability experiment. Base N = `subs_base_mlogN'; Covariates N = `subs_adj_mlogN'." "Full specification for Covariates model includes gender, age, racial ID, college degree, and party ID.", size(vsmall)) ///
				)	///
				subtitle(, size(small) margin(vsmall) justification(left) 			///
					color(white) bcolor(gray) bmargin(top_bottom)				///
					)					
graph display, ysize(4) xsize(6)

********************
* Appendix Table A12

esttab subs_base_mlog subs_adj_mlog												///
		using "${MyProject}AppendixTableA12.tex"							///
		, replace nobase label 	longtable  noomitted							///
		mtitles("Base" "Covariates")											///
		title("Substitutability Experiment Results" "\label{tab:substitutabilitymlogitres}")
		
	
* DYDX (Figure 6 c)


	est restore subs_adj_mlog
	margins , atmeans dydx(subs_treatment) post
	est sto subs_adj_mlog_fx


mylabels -15(5)10, myscale(@/100) local(myla)

coefplot (subs_adj_mlog_fx, keep(1.subs_treatment:*) label(Humanitarian))		///
		(subs_adj_mlog_fx, keep(3.subs_treatment:*) label(Economics))			///
		, recast(bar) vertical barw(0.25)										///
		noci																	///
		xlab(1 "No intervention" 2 "Anytime" 3 "Post" 4 "Pre",					///
				labsize(vsmall)) 												///
		title("{bf:C) Differences in Predicted Outcomes}", size(medsmall) span) 	///
		subtitle("{it:Base is Leadership Condition}", size(vsmall) span)		///
		ylab(`myla',labsize(vsmall))											///
		name(gph_dydx, replace) 												///
		ytitle("Difference between base and treatment", size(vsmall)) 			///
		legend(rows(1) ring(2) pos(12)) yline(0)		


********************
* Main Paper Figure 6

graph combine gph_subs_treatment gph_overall gph_dydx, ///
	rows(3)
graph display, ysize(9) xsize(6)
gr export "${MyProject}00 Main Figure 6.pdf", replace
		
		
* Subgroups


* Democrats
mlogit 	subs_DV_main b2.subs_treatment 											///
						age white female college if pid7 <= 3 
est sto subs_dem

* Republicans
mlogit 	subs_DV_main b2.subs_treatment 											///
						age white female college if pid7 >= 5 & pid7 < 8
est sto subs_gop


* Women
mlogit 	subs_DV_main b2.subs_treatment 											///
						age white  college i.pid3 if female == 1
est sto subs_fem

* Men
mlogit 	subs_DV_main b2.subs_treatment 											///
						age white  college i.pid3 if female == 0
est sto subs_male


* College
mlogit 	subs_DV_main b2.subs_treatment 											///
						age white female i.pid3 if college  == 1
est sto subs_college

* No College
mlogit 	subs_DV_main b2.subs_treatment 											///
						age white female college i.pid3 if college == 0
est sto subs_nocoll

* News interest
mlogit 	subs_DV_main b2.subs_treatment 											///
						age white female i.pid3 college if newsint_num  == 1
est sto subs_news1

mlogit 	subs_DV_main b2.subs_treatment 											///
						age white female i.pid3 college if newsint_num  == 2
est sto subs_news2

mlogit 	subs_DV_main b2.subs_treatment 											///
						age white female i.pid3 college if newsint_num  == 3
est sto subs_news3

********************
* Appendix Table A13

esttab subs_dem subs_gop subs_fem subs_male subs_news1 subs_news2 	subs_news3		///
		using "${MyProject}AppendixTableA13.tex"				///
	, replace nobase varwidth(25) noomitted label		longtable				///
	mtitles("Democrats" "Republicans" "Women" "Men" "News Mostly" "News Some" "News Rarely")		///
		title("Substitutability Experiment Subset" "\label{tab:substitutabilitymlogitsubset}")		
		
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
* Testing pre-registered hypotheses
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

***** Now, we run a variety of models for support of each strategy in a loop.

***** This sets up reporting of the pre-registered hypotheses (listed below).

lab var subs_contribute "Contribute funds"
lab var subs_concessionbefore "Concession before election"
lab var subs_coup "Encourage a coup"
lab var subs_concessionafter "Concession after election"
lab var subs_sanctions "Sanctions after election"

local strategies contribute concessionbefore coup concessionafter sanctions
	
foreach var of local strategies {
	local title: variable label subs_`var'

	* Base model (no covariates)
	local modelname olog
	quietly ologit subs_`var' b2.subs_treatment 
	local n1 = e(N)
	eststo strat_`var'_base
	
	* Include demographic variables
	
	quietly ologit subs_`var' b2.subs_treatment 		///
		age white female college i.pid7
	local n2 = e(N)
	eststo strat_`var'_cov
	
	* generate a coefplot for base and covariates
	
	coefplot 	(strat_`var'_base, label(Treatments Only, N=`n1'))				///
				(strat_`var'_cov, label(With Covariates, N=`n2'))				///
				, title(`title')												///
				keep(*subs*) base											///
				name(g_`var'_`modelname', replace)  xline(0) 					///
				legend(ring(0) pos(3) rows(2) size(vsmall)) 					///
				ylab(,labsize(vsmall))								
		
	}

********************
* Appendix Figure A8
	
grc1leg g_contribute_olog g_coup_olog g_concessionbefore_olog g_concessionafter_olog g_sanctions_olog		///
	, rows(3) title("{bf: Results by Strategy, Substitutability Experiment}")			///
	subtitle("{it: Ordinal Logistic Regression Coefficients}")					///
	note("Covariates model includes age, white racial ID, female gender ID, college degree, and party ID.",size(vsmall))																///
	xcommon
	
gr export "${MyProject}01 Figure A8.pdf", replace

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
* Dichotomous (Intervention or No)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

* Treatment only

logit 	subs_DV_any b2.subs_treatment
est sto subs_base_dichot_log, title("Base, Logit")
local 	subs_base_dichot_logN = e(N)

* With demographics
logit 	subs_DV_any b2.subs_treatment 											///
						age white female college i.pid7
est sto subs_adj_dichot_log, title("Adj, Logit")
local 	subs_adj_dichot_logN = e(N)
	
* Coefplot
local gtitle gph_overall_log
coefplot	(subs_base_dichot_log,label(Base))									///
			(subs_adj_dichot_log, label(Covariates))								///
			, title("{bf: Effects of Treatment on Intervention Support}", span)	///
			xtitle("{it: Logistic Coefficients}", size(small))	///
			keep(*.subs*) base												///
			headings(1.subs_treatment = "{bf:Treatment}"							///
						, labsize(vsmall))										///
			name(`gtitle',replace)  xline(0) 									///
			legend(ring(0) pos(10) rows(4) size(small)) 							///
			ylab(,labsize(vsmall))												///
			note("2022 CES Hegemony experiment. Base N = `subs_base_dichot_logN'; Covariates N = `subs_adj_dichot_logN'." "Full specification for Adjusted includes party ID, gender, age, racial ID, college degree, and party ID.", size(vsmall))
	
* Substantive
	est restore subs_base_dichot_log
	margins subs_treatment, atmeans post 
	est sto subs_base_dichot_logpost, title("Base")


	est restore subs_adj_dichot_log
	margins subs_treatment, atmeans post 
	est sto subs_adj_dichot_logpost, title("Covariates")

mylabels 0(10)50, myscale(@/100) local(myla)

coefplot (subs_base_dichot_logpost, label(Base)) 								///
		 (subs_adj_dichot_logpost, label(Covariates)) 							///
		 ,	///
			recast(bar) barw(0.15) vertical  									///
			ciopts(recast(rcap) color(gs8)) citop 								///
		xlab(1 "Humanitarian" 2 "Leadership" 3 "Economics",						///
				labsize(vsmall)) 												///
		title("{bf:Predicted Acceptability Evaluations}", span size(medsmall)) 	///
		yline(0) ylab(`myla',labsize(vsmall))									///
		ytitle("Predicted share", size(vsmall)) 								///
		name(gph_Predicted, replace) legend(rows(1) ring(2) pos(1))
		
* DYDX
est restore subs_base_dichot_log
margins, atmeans dydx(subs_treatment) post
est sto subs_base_dichot_logdydx

est restore subs_adj_dichot_log
margins, atmeans dydx(subs_treatment) post
est sto subs_adj_dichot_logdydx

mylabels 0(5)20, myscale(@/100) local(myla)

coefplot (subs_base_dichot_logdydx, label(Base))										///
		(subs_adj_dichot_logdydx, label(Covariates))										///
		, recast(bar) vertical barw(0.25)											///
		ciopts(recast(rcap) color(gs8)) citop										///
		xlab(1 "Humanitarian" 2 "Economics",										///
				labsize(vsmall)) 													///
		title("{bf:Differences in Predicted Outcomes}", size(medsmall) span) 		///
		subtitle("{it:Base is Leadership Condition}", size(vsmall) span)			///
		ylab(`myla',labsize(vsmall))												///
		name(gph_dydx, replace) 													///
		ytitle("Difference between base and treatment", size(vsmall)) 				///
		legend(rows(1) ring(2) pos(12)) 
	
********************
* Appendix Figure A9
		
gr combine gph_overall_log gph_Predicted gph_dydx, rows(3) 						///
	title("Substitutability Results")
graph display, ysize(8) xsize(6)
gr export "${MyProject}01 Figure A9.pdf", replace

